<template>
  <div class="book-item" @click.stop="toDetail(book)">
    <div
      class="img-box"
      :style="{
        backgroundImage: `url(${
          book.link.filter((item) => item.type == 'image/png')[0].href
        })`,
      }"
    ></div>
    <div class="my-text title">{{ book.title }}</div>
    <div class="my-text read-no">还有{{ surplusPage }}章未读</div>
  </div>
</template>

<script>
export default {
  props: ["book",'changeStatus'],
  data: () => {
    return {
      allPage: null,
      surplusPage: null,
    };
  },
  watch:{
    changeStatus(){
      this.changeInfo();
    }
  },
  methods: {
    toDetail(book) {
      this.$router.push({
        name: "detail",
        params: {
          bookid: book.id,
          title: book.title,
        },
      });
    },
    changeInfo() {
      this.allPage = Number.parseInt(
        this.book["pris:book"].totalArticleCount[0]
      );
      console.log(this.allPage);
      let book = JSON.parse(localStorage.getItem("readHistory")) || [];
      let page = 1;
      [].forEach.call(book, (item) => {
        if (item.bookInfo.id == this.book.id) {
          page = item.page;
        }
      });
      this.surplusPage = this.allPage - page;
    },
  },
  created() {
    this.changeInfo();
  },
};
</script>

<style lang="scss" scoped>
.book-item {
  width: 0.92rem;
  margin-bottom: 0.2rem;
  .img-box {
    width: 100%;
    aspect-ratio: 92/128;
  }
  .title {
    height: 0.3rem;
    margin: 0.1rem 0;
    font-size: 0.13rem;
    line-height: 0.15rem;
    -webkit-line-clamp: 2;
  }
  .read-no {
    font-size: 0.12rem;
    color: var(--text-gray);
  }
}
</style>